<?php
/**
 * Debug Perform.
 *
 * PHP versions 5
 * CAKEPHP versions 2.x
 * 
 * Green CMS - Content Management System and Framework Powerfull by Cakephp
 * Copyright 2012, GREEN GLOBAL CO., LTD (toancauxanh.vn)
 * 
 * CakePHP(tm) :  Rapid Development Framework (http://www.cakephp.org)
 * Copyright 2005-2011, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @author        Technology Lab No.I <tech1@toancauxanh.vn>
 * @link          
 * @package       Green.Configure
 * @since         Green v 1.0
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
class DebugPerform {

    /**
     * Holds a start time process
     * 
     * @var int
     */
    protected static $_time = 0;

    /**
     * Holds a start memory use before start process
     * 
     * @var int
     */
    protected static $_memory = 0;

    /**
     * Used to set time started process
     *
     * Examples:
     * 
     * `DebugPerform::start()` will set time startup
     * 
     * @return void
     */
    public static function start() {
        self::$_time = microtime(true);
        self::$_memory = memory_get_usage();
    }

    /**
     * Used to set time started process
     *
     * Examples:
     * 
     * `DebugPerform::stop()` will set time startup
     * 
     * @return void
     */
    public static function stop($exit = true) {
        echo "<pre style=\"background-color:#D2D6D6;border:2px solid #000;padding:10px;\">";
        echo "<b>Time Process:</b> <span style=\"color:#f00\">" . sprintf('%.5f ms',(microtime(true) - self::$_time)) . "</span>\n";
        $memory = (memory_get_usage() - self::$_memory) / 1024 / 1024;
        echo "<b>Memory Process:</b> <span style=\"color:#0C9A4C\">" . sprintf('%.5f MB', $memory) . "</span>\n";
        echo "</pre>";
        if ($exit) {
            exit(0);
        }
        self::start();
    }

}

?>
